package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;

public class SWITCH extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 2)
      return Primitive.ERROR_NAME;
    int i = 0;
    while (i < paramArrayOfObject.length)
    {
      if (i + 1 >= paramArrayOfObject.length)
        return paramArrayOfObject[i];
      if (Boolean.TRUE.equals(paramArrayOfObject[i]))
        return paramArrayOfObject[(i + 1)];
      i += 2;
    }
    return Primitive.NULL;
  }

  public Function.Type getType()
  {
    return Function.LOGIC;
  }

  public String getCN()
  {
    return "switch(表达式, 值1, 结果1, 值2, 结果2, ...)\n如果表达式的结果是值1，整个函数返回结果1\n如果表达式的结果是值2，整个函数返回结果2\n如果表达式的结果是值3，整个函数返回结果3\n等等\n";
  }

  public String getEN()
  {
    return "";
  }
}